#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N = 1e5 + 10, M = N * 2;
int h[N], e[M], ne[M], idx;
int temp[5];
int n, m;
int sz[N];
int ans1, ans2, ans = 1e9;
int d[N];
int cnt, edge1, edge2;
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void dfs(int u, int fa)
{
	sz[u] = 1;
	int ma = 0;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j == fa)continue;
		dfs(j, u);
		ma = max(ma, sz[j]);
		sz[u] += sz[j];
	}
	ma = max(ma, n - sz[u]);
	ans = min(ma, ans);
}
void dfs1(int u, int fa)
{
	sz[u] = 1;
	int ma = 0;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j == fa)continue;
		dfs1(j, u);
		ma = max(ma, sz[j]);
		sz[u] += sz[j];
	}
	ma = max(ma, n - sz[u]);
	if (ma == ans) {
		temp[++cnt] = u;
	}
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		//int root = 1;
		ans1 = 0, ans2 = 0, ans = 1e9;
		cnt = 0;
		idx = 0;
		memset(temp, 0, sizeof(temp));
		memset(h, -1, sizeof(h));
		/*memset(h, -1, sizeof(h));
		memset(sz, 0, sizeof(sz));
		memset(ne, 0, sizeof(ne));
		memset(e, 0, sizeof(e));
		memset(temp, 0, sizeof(temp));
		memset(d, 0, sizeof(d));*/
		for (int i = 0; i < n - 1; i++) {
			int a, b;
			scanf_s("%d%d", &a, &b);
			edge1 = a, edge2 = b;
			add(a, b);
			add(b, a);
			//d[b]++;
		}
		/*for (int i = 1; i <= n; i++) {
			if (!d[i]) {
				root = i;
				break;
			}
		}*/
		dfs(1, 0);
		//cout << ans << endl;
		//cout << ans1 << "  " << ans2 << endl;
		dfs1(1, 0);
		/*for (int i = 1; i <= cnt; i++) {
			cout << "temp[i]===" << temp[i] << endl;
		}*/
		cout << "cnt==" << cnt << endl;
		if (cnt == 1) {
			cout << edge1 << " " << edge2 << endl;
			cout << edge1 << " " << edge2 << endl;
		}
		else {
			int a = temp[1];                                                                                                            
			int b = temp[2];
			int idx = 0;
			for (int i = h[a]; ~i; i = ne[i]) {
				int j = e[i];
				if (j == b)continue;
				idx = j;
				cout << a << " " << j << endl;
				break;
			}
			cout << idx << " " << b << endl;
		}
	}
	return 0;
}
/*
1
4
1 4
3 4
2 3
*/